var mysql = require('mysql');
var conf = require('../config/mysql');

var pool = mysql.createPool(conf);

function query(sql) {
  return new Promise((resovle, reject) => {
    pool.getConnection(function (err, connection) {
      connection.query(sql, [], function (err, result) {
        if (err) {
          reject(err);
        } else {
          resovle(result);
        }
        connection.release();
      });
    });
  });
}

module.exports = {
  pool,
  query
};